package bigraph.part;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;

import bigraph.editpolicies.AppDeletePolicy;
import bigraph.editpolicies.AppEditLayoutPolicy;
import bigraph.editpolicies.AppRenamePolicy;
import bigraph.figure.SiteFigure;
import bigraph.model.Node;
import bigraph.model.Site;

public class SitePart extends AppAbstractEditPart {

	@Override
	protected IFigure createFigure() {
		IFigure figure = new SiteFigure();
		return figure;
	}

	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new AppEditLayoutPolicy());
		installEditPolicy(EditPolicy.COMPONENT_ROLE,new AppDeletePolicy());
		installEditPolicy(EditPolicy.NODE_ROLE, new AppRenamePolicy());
	}

	
	protected void refreshVisuals(){
	     SiteFigure figure = (SiteFigure)getFigure();
	     Site model = (Site)getModel();
	     figure.setName(model.getName());
	     figure.setLayout(model.getLayout());
	     figure.setColor(model.getColor());
	}
	public List<Node> getModelChildren() {
	    return new ArrayList<Node>();
	}
	
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
	     if (evt.getPropertyName().equals(Node.PROPERTY_LAYOUT)) refreshVisuals();
	     if (evt.getPropertyName().equals(Node.PROPERTY_ADD)) refreshChildren();
	     if (evt.getPropertyName().equals(Node.PROPERTY_REMOVE)) refreshChildren();
	     if (evt.getPropertyName().equals(Node.PROPERTY_RENAME)) refreshVisuals();
	     if (evt.getPropertyName().equals(Site.PROPERTY_COLOR)) refreshVisuals();
	}



}
